import moment from 'moment'
export function formatPriceNumber(number, decimal = 2) {
  let priceNumber = number
  if (typeof priceNumber === 'string') {
    priceNumber = priceNumber.replace(/[^\d.]/gi, '')
  }
  var price = parseFloat(priceNumber)
  if (isNaN(price)) {
    return number
  }
  if (decimal === false) {
    return price
  }
  return price.toFixed(decimal).toString()
}
export default class formatter {
  asCurrency(row, column, cellValue, index) {
    var currency = formatPriceNumber(cellValue)
    return '￥' + currency
  }
  asDatetime(row, column, cellValue, index) {
    var time = cellValue * 1000
    return moment(time).format('YYYY-MM-DD HH:mm:ss')
  }
}
